package Bench::Test::Entry;

use 5.008004;
use strict;
use warnings;

use Switch;

#============================================================================== 
# Object Constructor.
# - Inputs:  Classname and configuration file
# - Outputs: The blessed reference
#============================================================================== 
sub new {
   my ($class, %params) = @_;
   my %UNIQUE = ( TEST => 1, NAME => 1 );
   map { $UNIQUE{$_} = 1 } @{$params{unique}};

   return bless { 
                  FIELDS    => $params{fields}, 
                  EXP_NAMES => $params{exp_names},
                  UNIQUE    => \%UNIQUE,
                }, $class;
}

sub set_field_value {
   my $self = shift;
   my ($field, $exp_name, $value) = @_;
   if ($self->{UNIQUE}{$field}) {
      $self->{$field} = $value;
   }
   else { 
      $self->{$field}{$exp_name} = $value;
   }
}

sub set_test_field {
   my $self = shift;
   $self->{TEST} = $self->is_OK() ? 'ok' : 'Fail';
}

sub set_name_field {
   my ($self, $name) = @_;
   $self->{NAME} = $name;
   # Usar constantes
}

sub get_field_value {
   my $self = shift;
   my ($field, $exp_name) = @_;
  
   return $self->{$field} if $self->{UNIQUE}{$field};
   return $self->{$field}{$exp_name};
}

# =================================================
# Get_fields, devuelve todos los campos que son
# analizados. Es util para utilizar dentro de la
# funcion is_Ok para hacer una comprobacion sobre
# todos los campos, por ejemplo
# =================================================
sub get_fields {
   my $self = shift;
   return @{$self->{FIELDS}};
}

# =================================================
# Get_exp_names, devuelve todos los nombres de
# experimentos. Es útil para utilizar dentro de la
# funcion is_Ok para hacer una comprobacion sobre
# todos los experimentos
# =================================================
sub get_exp_names {
   my $self = shift;
   return @{$self->{EXP_NAMES}}
}

sub get_uniques {
   my $self = shift;
   return %{$self->{UNIQUE}};
}

sub get_field_names {
   my $self = shift;
   my @names = ();

   for my $field (@{$self->{FIELDS}}) {
      if ($self->{UNIQUE}{$field}) {
         push @names, $field;
         next;
      }
      for my $exp_name (@{$self->{EXP_NAMES}}) {
         push @names, "$field($exp_name)";
      }
   }
   return \@names;
}

sub get_field_values {
   my $self = shift;
   my @values = ();

   for my $field (@{$self->{FIELDS}}) {
      if ($self->{UNIQUE}{$field}) {
         push @values, $self->{$field};
         next;
      }
      for my $exp_name (@{$self->{EXP_NAMES}}) {
         push @values, $self->{$field}{$exp_name};
      }
   }
   return \@values;
}

1;

